/**********************************************************************************************************
** 驱动文件：	jmkt-SCAxxx.c
** 驱动类型：	jmkt
** 设备名称：	精密空调
** 设备型号：	SCAxxx
** 设备品牌：	依米康
** 设备协议：	Modbus-RTU
** 驱动描述：	适用于依米康SCA系列机房精密空调，协议为Modbus-RTU。
** 生成日期：	2019-05-19 17:30:37
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var returnAirTemperature;					//回风温度
	Var returnAirHumidity;						//回风湿度
	Var setTemperature;							//设定温度
	Var setHumidity;							//设定湿度
	Var onoff;									//开关机状态
	Var fanStatus;								//风机状态
	Var coolingStatus;							//制冷状态
	Var heatingStatus;							//加热状态
	Var humidificationStatus;					//加湿状态
	Var dehumidificationStatus;					//除湿状态
	Var groupControlMode;						//单机/群控模式
	Var compressor1PressureAlarm;				//压缩机1高/低压告警
	Var compressor2PressureAlarm;				//压缩机2高/低压告警
	Var compressor1PressureLock;				//压缩机1高/低压锁死
	Var compressor2PressureLock;				//压缩机2高/低压锁死
	Var returnAirTemperatureAlarm;				//回风温度告警
	Var returnAirHumidityAlarm;					//回风湿度告警
	Var supplyAirTemperatureAlarm;				//送风温度告警
	Var fanFailure;								//风机故障
	Var fanTimeout;								//风机超时
	Var airflowLossAlarm;						//气流丢失
	Var heaterOverload;							//加热器过载
	Var filterBlockage;							//过滤网堵塞
	Var filterTimeout;							//过滤网超时
	Var humidifierOverload;						//加湿器电流过大
	Var humidifierDryBurning;					//加湿器干烧
	Var humidifierTimeout;						//加湿器超时
	Var humidifierFailure;						//加湿器故障
	Var leakageAlarm;							//漏水告警
	Var remoteShutdown;							//远程关机
	Var groupControlAnomaly;					//群控异常
	Var compressor1ShortCycle;					//压缩机1短周期
	Var compressor2ShortCycle;					//压缩机2短周期
	Var compressor1Timeout;						//压缩机1超时
	Var compressor2Timeout;						//压缩机2超时
	Var heater1Timeout;							//加热器１超时
	Var heater2Timeout;							//加热器２超时
	Var smokeAlarm;								//烟雾告警
	Var powerFailureAlarm;						//掉电告警
	Var powerFrequency;							//电源频率
	Var APhaseVoltage;							//A相电压
	Var BPhaseVoltage;							//B相电压
	Var CPhaseVoltage;							//C相电压
	Var fanRunTime;								//风机运行时间
	Var compressor1RunTime;						//压缩机1运行时间
	Var compressor2RunTime;						//压缩机2运行时间
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		FLOAT,
		0,
		READONLY,
		"returnAirTemperature",
		"回风温度",
		"℃",
		"回风温度",
		0,
		0,
		"回风温度过高",
		"回风温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"returnAirHumidity",
		"回风湿度",
		"%",
		"回风湿度",
		0,
		0,
		"回风湿度过高",
		"回风湿度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setTemperature",
		"设定温度",
		"℃",
		"空调设定温度值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"setHumidity",
		"设定湿度",
		"%",
		"空调设定湿度值",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"onoff",
		"开关机状态",
		"",
		"空调开关机状态：0-关机；1-开机",
		0,
		0,
		"空调关机",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fanStatus",
		"风机状态",
		"",
		"风机状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"coolingStatus",
		"制冷状态",
		"",
		"制冷状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heatingStatus",
		"加热状态",
		"",
		"加热状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidificationStatus",
		"加湿状态",
		"",
		"加湿状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"dehumidificationStatus",
		"除湿状态",
		"",
		"除湿状态：0-停止；1-运行",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"groupControlMode",
		"单机/群控模式",
		"",
		"单机/群控模式：0-单机模式；1-群控模式",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor1PressureAlarm",
		"压缩机1高/低压告警",
		"",
		"压缩机高压、低压告警：0-无告警；1-高压告警；2-低压告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor2PressureAlarm",
		"压缩机2高/低压告警",
		"",
		"压缩机2高压、低压告警：0-无告警；1-高压告警；2-低压告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor1PressureLock",
		"压缩机1高/低压锁死",
		"",
		"压缩机1高/低压锁死：0-无锁死；1-锁死",
		0,
		0,
		"锁死",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor2PressureLock",
		"压缩机2高/低压锁死",
		"",
		"压缩机2高/低压锁死：0-无锁死；1-锁死",
		0,
		0,
		"锁死",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"returnAirTemperatureAlarm",
		"回风温度告警",
		"",
		"回风温度告警：0-无告警；1-高温告警；2-低温告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"returnAirHumidityAlarm",
		"回风湿度告警",
		"",
		"回风湿度告警：0-无告警；1-髙湿告警；2-低湿告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"supplyAirTemperatureAlarm",
		"送风温度告警",
		"",
		"送风温度告警：0-无告警；1-高温告警；2-低温告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fanFailure",
		"风机故障",
		"",
		"风机故障：0-无故障；1-有故障",
		0,
		0,
		"有故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"fanTimeout",
		"风机超时",
		"",
		"风机超时：0-无超时；1-有超时",
		0,
		0,
		"有超时",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"airflowLossAlarm",
		"气流丢失",
		"",
		"气流丢失：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heaterOverload",
		"加热器过载",
		"",
		"加热器过载：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"filterBlockage",
		"过滤网堵塞",
		"",
		"过滤网堵塞：0-无堵塞；1-有堵塞",
		0,
		0,
		"有堵塞",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"filterTimeout",
		"过滤网超时",
		"",
		"过滤网超时：0-无超时；1-有超时",
		0,
		0,
		"有故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidifierOverload",
		"加湿器电流过大",
		"",
		"加湿器电流过大：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidifierDryBurning",
		"加湿器干烧",
		"",
		"加湿器干烧：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidifierTimeout",
		"加湿器超时",
		"",
		"加湿器超时：0-无超时；1-有超时",
		0,
		0,
		"有超时",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"humidifierFailure",
		"加湿器故障",
		"",
		"加湿器故障：0-无故障；1-有故障",
		0,
		0,
		"有故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"leakageAlarm",
		"漏水告警",
		"",
		"漏水告警：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"remoteShutdown",
		"远程关机",
		"",
		"远程关机：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"groupControlAnomaly",
		"群控异常",
		"",
		"群控异常：0-无异常；1-有异常",
		0,
		0,
		"有异常",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor1ShortCycle",
		"压缩机1短周期",
		"",
		"压缩机1短周期：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor2ShortCycle",
		"压缩机2短周期",
		"",
		"压缩机2短周期：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor1Timeout",
		"压缩机1超时",
		"",
		"压缩机1超时：0-无超时；1-有超时",
		0,
		0,
		"有超时",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"compressor2Timeout",
		"压缩机2超时",
		"",
		"压缩机2超时：0-无超时；1-有超时",
		0,
		0,
		"有超时",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heater1Timeout",
		"加热器１超时",
		"",
		"加热器１超时：0-无超时；1-有超时",
		0,
		0,
		"有超时",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"heater2Timeout",
		"加热器２超时",
		"",
		"加热器2超时：0-无超时；1-有超时",
		0,
		0,
		"有超时",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"smokeAlarm",
		"烟雾告警",
		"",
		"烟雾告警：0-无告警；1-有告警",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"powerFailureAlarm",
		"掉电告警",
		"",
		"掉电告警：0-无故障；1-有故障",
		0,
		0,
		"有故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"powerFrequency",
		"电源频率",
		"",
		"电源频率：0-正常；1-频率偏高；2-频率偏低",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"APhaseVoltage",
		"A相电压",
		"",
		"A相电压：0-正常；1-过压；2-低压；3-缺相",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BPhaseVoltage",
		"B相电压",
		"",
		"B相电压：0-正常；1-过压；2-低压；3-缺相",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"CPhaseVoltage",
		"C相电压",
		"",
		"C相电压：0-正常；1-过压；2-低压；3-缺相",
		0,
		0,
		"有告警",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"fanRunTime",
		"风机运行时间",
		"秒",
		"风机运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"compressor1RunTime",
		"压缩机1运行时间",
		"秒",
		"压缩机1运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		INTEGER,
		0,
		READONLY,
		"compressor2RunTime",
		"压缩机2运行时间",
		"秒",
		"压缩机2运行时间",
		0,
		0,
		"",
		"",
		0,
		0
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:
			cmd[0] = addr;
			cmd[1] = 0x03;
			cmd[2] = 0x00;								
			cmd[3] = 0x00;
			cmd[4] = 0x00;
			cmd[5] = 0x15;
			*len = CRC16_Padding(cmd, 6);
			break;
		default:
			break;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	union{
		short 			dat16;
      	unsigned char  	dat8[2];
    }DAT16_8;						   //数据类型转换	
	Data_Struct 	*d = (Data_Struct*)data;
	
	if(buf!=NULL && buf[0]==addr && len>0 )
	{	
		if(CRC16_Check(buf,len))
		{	
			DAT16_8.dat8[1] = buf[5];
			DAT16_8.dat8[0] = buf[6];
			d->setTemperature.value.fnum = DAT16_8.dat16*0.1;
			DAT16_8.dat8[1] = buf[7];
			DAT16_8.dat8[0] = buf[8];
			d->setHumidity.value.fnum = DAT16_8.dat16*0.1;
			DAT16_8.dat8[1] = buf[11];
			DAT16_8.dat8[0] = buf[12];
			d->returnAirTemperature.value.fnum = DAT16_8.dat16*0.1;			
			DAT16_8.dat8[1] = buf[13];
			DAT16_8.dat8[0] = buf[14];
			d->returnAirHumidity.value.fnum = DAT16_8.dat16*0.1;					

			d->dehumidificationStatus.value.str 	  = buf[10]&0x20?"运行":"停止";
			Set_Var_Status(&d->dehumidificationStatus,	buf[10]&0x20?ON:OFF, NULL);	
			d->humidificationStatus.value.str		  = buf[10]&0x10?"运行":"停止";
			Set_Var_Status(&d->humidificationStatus,	buf[10]&0x10?ON:OFF, NULL);	
			d->coolingStatus.value.str				  = buf[10]&0x08?"运行":"停止";
			Set_Var_Status(&d->coolingStatus,			buf[10]&0x08?ON:OFF, NULL);	
			d->heatingStatus.value.str				  = buf[10]&0x04?"运行":"停止";
			Set_Var_Status(&d->heatingStatus,			buf[10]&0x04?ON:OFF, NULL);	
			d->fanStatus.value.str					  = buf[10]&0x02?"运行":"停止";
			Set_Var_Status(&d->fanStatus,				buf[10]&0x02?ON:OFF, NULL);	
			d->onoff.value.str						  = buf[10]&0x01?"开机":"关机";
			Set_Var_Status(&d->onoff,					buf[10]&0x01?Normal:Alarm, NULL);

			d->groupControlMode.value.str 			  = buf[9]&0x01?"群控模式":"单机模式";

			if(buf[16]&0x01){
				d->returnAirTemperatureAlarm.value.str	= "高温告警";
				Set_Var_Status(&d->returnAirTemperatureAlarm, Alarm, "高温告警");
			}
			else if(buf[16]&0x02){
				d->returnAirTemperatureAlarm.value.str	= "低温告警";
				Set_Var_Status(&d->returnAirTemperatureAlarm, Alarm, "低温告警");
			}
			else{
				d->returnAirTemperatureAlarm.value.str	= "无告警";
				Set_Var_Status(&d->returnAirTemperatureAlarm, Normal, "无告警");
			}

			if(buf[16]&0x04){
				d->returnAirHumidityAlarm.value.str		= "高湿告警";
				Set_Var_Status(&d->returnAirHumidityAlarm, Alarm, "高湿告警");
			}
			else if(buf[16]&0x08){
				d->returnAirHumidityAlarm.value.str		= "低湿告警";
				Set_Var_Status(&d->returnAirHumidityAlarm, Alarm, "低湿告警");
			}
			else{
				d->returnAirHumidityAlarm.value.str		= "无告警";
				Set_Var_Status(&d->returnAirHumidityAlarm, Normal, "无告警");
			}

			if(buf[16]&0x10){
				d->supplyAirTemperatureAlarm.value.str	= "高温告警";
				Set_Var_Status(&d->supplyAirTemperatureAlarm, Alarm, "高温告警");
			}
			else if(buf[16]&0x20){
				d->supplyAirTemperatureAlarm.value.str	= "低温告警";
				Set_Var_Status(&d->supplyAirTemperatureAlarm, Alarm, "低温告警");
			}
			else{
				d->supplyAirTemperatureAlarm.value.str	= "无告警";
				Set_Var_Status(&d->supplyAirTemperatureAlarm, Normal, "无告警");
			}

			d->fanFailure.value.str			= buf[15]&0x08?"有故障":"无故障";
			Set_Var_Status(&d->fanFailure, 	  buf[15]&0x08?Alarm:Normal, NULL);

			d->fanTimeout.value.str			= buf[18]&0x02?"有告警":"无告警";
			Set_Var_Status(&d->fanTimeout, 	  buf[18]&0x02?Alarm:Normal, NULL);

			if(buf[18]&0x80){
				d->compressor1PressureAlarm.value.str	= "高压告警";
				Set_Var_Status(&d->compressor1PressureAlarm, Alarm, "高压告警");
			}
			else if(buf[17]&0x02){
				d->compressor1PressureAlarm.value.str	= "低压告警";
				Set_Var_Status(&d->compressor1PressureAlarm, Alarm, "低压告警");
			}
			else{
				d->compressor1PressureAlarm.value.str	= "无告警";
				Set_Var_Status(&d->compressor1PressureAlarm, Normal, "无告警");
			}

			if(buf[17]&0x80){
				d->compressor2PressureAlarm.value.str	= "高压告警";
				Set_Var_Status(&d->compressor2PressureAlarm, Alarm, "高压告警");
			}
			else if(buf[20]&0x02){
				d->compressor2PressureAlarm.value.str	= "低压告警";
				Set_Var_Status(&d->compressor2PressureAlarm, Alarm, "低压告警");
			}
			else{
				d->compressor2PressureAlarm.value.str	= "无告警";
				Set_Var_Status(&d->compressor2PressureAlarm, Normal, "无告警");
			}

			if(buf[17]&0x01){
				d->compressor1PressureLock.value.str	= "高压锁死";
				Set_Var_Status(&d->compressor1PressureLock, Alarm, "高压锁死");
			}
			else if(buf[17]&0x04){
				d->compressor1PressureLock.value.str	= "低压锁死";
				Set_Var_Status(&d->compressor1PressureLock, Alarm, "低压锁死");	
			}
			else{
				d->compressor1PressureLock.value.str	= "无锁死";
				Set_Var_Status(&d->compressor1PressureLock, Normal, "无锁死");
			}

			if(buf[20]&0x01){
				d->compressor2PressureLock.value.str	= "高压锁死";
				Set_Var_Status(&d->compressor2PressureLock, Alarm, "高压锁死");
			}
			else if(buf[20]&0x04){
				d->compressor2PressureLock.value.str	= "低压锁死";
				Set_Var_Status(&d->compressor2PressureLock, Alarm, "低压锁死");	
			}
			else{
				d->compressor2PressureLock.value.str	= "无锁死";
				Set_Var_Status(&d->compressor2PressureLock, Normal, "无锁死");
			}
			
			d->compressor1ShortCycle.value.str			= buf[17]&0x20?"有告警":"无告警";
			Set_Var_Status(&d->compressor1ShortCycle, 	  buf[17]&0x20?Alarm:Normal, NULL);

			d->compressor1Timeout.value.str				= buf[17]&0x40?"有超时":"无超时";
			Set_Var_Status(&d->compressor1Timeout,		  buf[17]&0x40?Alarm:Normal, NULL);
			
			d->compressor2ShortCycle.value.str			= buf[20]&0x20?"有告警":"无告警";
			Set_Var_Status(&d->compressor2ShortCycle, 	  buf[20]&0x20?Alarm:Normal, NULL);

			d->compressor2Timeout.value.str				= buf[20]&0x40?"有超时":"无超时";
			Set_Var_Status(&d->compressor2Timeout,		  buf[20]&0x40?Alarm:Normal, NULL);

			d->humidifierOverload.value.str				= buf[20]&0x80?"有告警":"无告警";
			Set_Var_Status(&d->humidifierOverload, 		  buf[20]&0x80?Alarm:Normal, NULL);	
			
			d->humidifierDryBurning.value.str			= buf[19]&0x02?"有告警":"无告警";
			Set_Var_Status(&d->humidifierDryBurning, 	  buf[19]&0x02?Alarm:Normal, NULL);

			d->humidifierTimeout.value.str				= buf[19]&0x04?"有超时":"无超时";
			Set_Var_Status(&d->humidifierTimeout, 		  buf[19]&0x04?Alarm:Normal, NULL);

			d->heaterOverload.value.str					= buf[19]&0x08?"有告警":"无告警";
			Set_Var_Status(&d->heaterOverload, 			  buf[19]&0x08?Alarm:Normal, NULL);

			d->heater1Timeout.value.str					= buf[19]&0x10?"有超时":"无超时";
			Set_Var_Status(&d->heater1Timeout, 			  buf[19]&0x10?Alarm:Normal, NULL);

			d->heater2Timeout.value.str					= buf[19]&0x20?"有超时":"无超时";
			Set_Var_Status(&d->heater2Timeout, 			  buf[19]&0x20?Alarm:Normal, NULL);

			d->powerFailureAlarm.value.str				= buf[19]&0x40?"有告警":"无告警";
			Set_Var_Status(&d->powerFailureAlarm, 		  buf[19]&0x40?Alarm:Normal, NULL);
			
			if(buf[22]&0x01){
				d->powerFrequency.value.str	= "频率偏高";
				Set_Var_Status(&d->powerFrequency, Alarm, "频率偏高");
			}
			else if(buf[22]&0x02){
				d->powerFrequency.value.str	= "频率偏低";
				Set_Var_Status(&d->powerFrequency, Alarm, "频率偏低");	
			}
			else{
				d->powerFrequency.value.str	= "正常";
				Set_Var_Status(&d->powerFrequency, Normal, "正常");
			}

			if(buf[21]&0x01){
				d->APhaseVoltage.value.str	= "缺相";
				Set_Var_Status(&d->APhaseVoltage, Alarm, "缺相");
			}
			else if(buf[22]&0x04){
				d->APhaseVoltage.value.str	= "过压";
				Set_Var_Status(&d->APhaseVoltage, Alarm, "过压");
			}
			else if(buf[22]&0x20){
				d->APhaseVoltage.value.str	= "欠压";
				Set_Var_Status(&d->APhaseVoltage, Alarm, "欠压");
			}			
			else{
				d->APhaseVoltage.value.str	= "正常";
				Set_Var_Status(&d->APhaseVoltage, Normal, "正常");
			}

			if(buf[21]&0x02){
				d->BPhaseVoltage.value.str	= "缺相";
				Set_Var_Status(&d->BPhaseVoltage, Alarm, "缺相");
			}
			else if(buf[22]&0x08){
				d->BPhaseVoltage.value.str	= "过压";
				Set_Var_Status(&d->BPhaseVoltage, Alarm, "过压");
			}
			else if(buf[22]&0x40){
				d->BPhaseVoltage.value.str	= "欠压";
				Set_Var_Status(&d->BPhaseVoltage, Alarm, "欠压");
			}			
			else{
				d->BPhaseVoltage.value.str	= "正常";
				Set_Var_Status(&d->BPhaseVoltage, Normal, "正常");
			}

			if(buf[21]&0x04){
				d->CPhaseVoltage.value.str	= "缺相";
				Set_Var_Status(&d->CPhaseVoltage, Alarm, "缺相");
			}
			else if(buf[22]&0x10){
				d->CPhaseVoltage.value.str	= "过压";
				Set_Var_Status(&d->CPhaseVoltage, Alarm, "过压");
			}
			else if(buf[22]&0x80){
				d->CPhaseVoltage.value.str	= "欠压";
				Set_Var_Status(&d->CPhaseVoltage, Alarm, "欠压");
			}			
			else{
				d->CPhaseVoltage.value.str	= "正常";
				Set_Var_Status(&d->CPhaseVoltage, Normal, "正常");
			}

			d->airflowLossAlarm.value.str			= buf[21]&0x08?"有告警":"无告警";
			Set_Var_Status(&d->airflowLossAlarm, 	  buf[21]&0x08?Alarm:Normal, NULL);	

			d->filterTimeout.value.str				= buf[21]&0x10?"有超时":"无超时";
			Set_Var_Status(&d->filterTimeout, 		  buf[21]&0x10?Alarm:Normal, NULL);	

			d->filterBlockage.value.str				= buf[21]&0x20?"有堵塞":"无堵塞";
			Set_Var_Status(&d->filterBlockage, 		  buf[21]&0x20?Alarm:Normal, NULL);	

			d->remoteShutdown.value.str				= buf[21]&0x40?"有告警":"无告警";
			Set_Var_Status(&d->remoteShutdown, 		  buf[21]&0x40?Alarm:Normal, NULL);	

			d->leakageAlarm.value.str				= buf[21]&0x80?"有告警":"无告警";
			Set_Var_Status(&d->leakageAlarm, 		  buf[21]&0x80?Alarm:Normal, NULL);	

			d->groupControlAnomaly.value.str		= buf[24]&0x01?"有异常":"无异常";
			Set_Var_Status(&d->groupControlAnomaly,   buf[24]&0x01?Alarm:Normal, NULL);	

			d->smokeAlarm.value.str					= buf[24]&0x10?"有告警":"无告警";
			Set_Var_Status(&d->smokeAlarm, 			  buf[24]&0x10?Alarm:Normal, NULL);	

			d->humidifierFailure.value.str			= buf[26]&0x02?"有故障":"无故障";
			Set_Var_Status(&d->humidifierFailure, 	  buf[26]&0x02?Alarm:Normal, NULL);	
	
			d->fanRunTime.value.inum				= (buf[33]<<24)|(buf[34]<<16)|(buf[35]<<8)|buf[36];
			d->compressor1RunTime.value.inum		= (buf[37]<<24)|(buf[38]<<16)|(buf[39]<<8)|buf[40];
			d->compressor2RunTime.value.inum		= (buf[41]<<24)|(buf[42]<<16)|(buf[43]<<8)|buf[44];			
			return 0;		
		}
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void jmkt_SCAxxx_Registration(void)
* 函数说明： 依米康精密空调驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void jmkt_SCAxxx_Registration(void)
{
	DeviceDriverRegistration(
		"jmkt",													//设备类型
		"精密空调",												//设备名称（导航栏默认显示名称）
		"依米康",												//设备品牌	
		"SCAxxx",												//设备型号
		"适用于依米康SCA系列机房精密空调，协议为Modbus-RTU。",	//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		800														//设备响应超时时间		
	);
	
#if 0
	#define	CMD1	"\x01\x03\x00\x00\x00\x15\x84\x05"
	#define	RSP1	"\x01\x03\x2A\x00\x01\x00\xE6\x01\x90\x00\x27\x00\xD3\x02\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x9E\x58\x9C\x00\x31\xB0\x1B\x00\x00\x00\x00\x69\x3B"			
	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);					
#endif
}

